package com.yunbao.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunbao.core.respones.Result;
import com.yunbao.core.respones.ResultBuilder;
import com.yunbao.core.shiro.jwt.JwtUtil;
import com.yunbao.project.entity.Merchant;
import com.yunbao.project.mapper.MerchantMapper;
import com.yunbao.project.service.IMerchantService;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;

/**
 * <p>
 * 商家,店主 服务实现类
 * </p>
 *
 * @author 安能
 * @since 2019-09-16
 */
@Service
public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> implements IMerchantService {

    @Override
    public Result login(Merchant merchant) throws UnsupportedEncodingException {

        Merchant merchantOne = getOne(new QueryWrapper<Merchant>()
                .eq("user_name", merchant.getUserName())
                .eq("password", merchant.getPassword()));
        if (merchantOne != null) {
            return ResultBuilder.success(JwtUtil.sign(merchantOne));
        }
        return ResultBuilder.errorInfo(403,"用户名或者密码不正确");
    }
}
